// packageA/member/price_pool/price_pool.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 'capital_pool_records',
    performance_total: '',
    finished_quota: '',
    waiting_quota: '',
    capital_pool: '',
    capital_pool_records: {},//动余额资金池
    love_speed_pool:{},//直推奖
    diy_names:{},
    amount_total:''
  },
  onChange(e) {
    this.setData({
      active: e.detail.name
    })
  },
  //直推奖(收入明细)
  getAccountBalance(){
    app._getNetWork({
      url:  app.getNetAddresss('plugin.love-speed-pool.frontend.plus.index'),
      success: (res) => {
        if (res.data.result == 1) {
          this.setData({
            amount_total:res.data.data.amount_total,
            love_speed_pool: res.data.data.list,
          })
        }else{
          app.tips(res.data.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },

  RedPacket() {
    wx.navigateTo({
      url: '/packageA/member/redPacket/redPacket',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getData();//动静余额资金池
    this.getAccountBalance();//直推奖
  },
  getData() {
    //获取新的首页
    app._getNetWork({
      url: app.getNetAddresss('plugin.love-speed-pool.frontend.newHome.index'),
      success: (res) => {
        if (res.data.result == 1) {
          let {
            performance_total,
            finished_quota,
            waiting_quota,
            capital_pool,
            capital_pool_records,
            diy_name,
            diy_names
          } = res.data.data;
          this.setData({
            diy_names,
            diy_name,
            performance_total,
            finished_quota,
            waiting_quota,
            capital_pool,
            capital_pool_records
          })
          wx.setNavigationBarTitle({
            title: diy_name || '资金池',
          })
        } else {
          app.tips(res.data.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.active == 'capital_pool_records'){
      if(this.data.capital_pool_records.current_page>=this.data.capital_pool_records.last_page){
        return false;
      }
      let page = this.data.capital_pool_records.current_page+1;
      app._getNetWork({
        url:app.getNetAddresss('plugin.love-speed-pool.frontend.newHome.index'),
        data:{
          page
        },
        success: (res) => {
          if (res.data.result == 1) {
            let {
              performance_total,
              finished_quota,
              waiting_quota,
              capital_pool,
              capital_pool_records
            } = res.data.data;
            let arr = this.data.capital_pool_records.data.concat(capital_pool_records.data);

            this.setData({
              performance_total,
              finished_quota,
              waiting_quota,
              capital_pool,
              "capital_pool_records.data":arr,
              "capital_pool_records.current_page":capital_pool_records.last_page
            })
          } else {
            app.tips(res.data.msg)
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    }else{
      if(this.data.love_speed_pool.current_page>=this.data.love_speed_pool.last_page){
        return false;
      }
      let page = this.data.love_speed_pool.current_page+1;
      app._getNetWork({
        url:  app.getNetAddresss('plugin.love-speed-pool.frontend.plus.index'),
        data:{
          page
        },
        success: (res) => {
          if (res.data.result == 1) {
            let arr =  this.data.love_speed_pool.data.concat(res.data.data.list.data)
            this.setData({
              "love_speed_pool.data":arr,
              "love_speed_pool.current_page":res.data.data.list.current_page
            })
          }else{
            app.tips(res.data.msg)
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})